import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { LibraryService } from 'src/app/core/service/library.service';

@Component({
  selector: 'app-lib-detail',
  templateUrl: './lib-detail.component.html',
  styleUrls: ['./lib-detail.component.scss']
})
export class LibDetailComponent implements OnInit {
  dataSet: any;
  applicationNum: any;
  libHash: string;
  data = [
    {
      title: 'Title 1'
    },
    {
      title: 'Title 2'
    },
    {
      title: 'Title 3'
    },
    {
      title: 'Title 4'
    },
    {
      title: 'Title 5'
    },
    {
      title: 'Title 6'
    }
  ];

  /**
     *
     * @param reset 获取数据
     */
  getLibraryDetailPage(reset: boolean = false): void {
    this.libraryservice.getLibraryDetailPage(this.libHash)
      .subscribe((libraryDetailPage) => {
        console.log(`===收到detail数据===> ${libraryDetailPage} ==长度==> ${libraryDetailPage}`);
        this.dataSet = libraryDetailPage;
        this.applicationNum = this.dataSet.applications.length;
        console.log('应用数量', this.dataSet.applications.length);
        // this.applicationNum = this.dataSet.applications;
        console.log('===datail现在的数据===', libraryDetailPage);
      });
  }
  constructor(
    private libraryservice: LibraryService,
    private routeInfo: ActivatedRoute
  ) { }

  ngOnInit() {
    this.libHash = this.routeInfo.snapshot.queryParams['hash'];
    console.log('hash值-->', this.libHash);
    this.getLibraryDetailPage();
  }

}
